package com.web.service.impl;

import com.web.service.DemoService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

@Service
@PropertySource("classpath:application.properties")
public class DemoServiceImpl implements DemoService {
    /**
     * @Value用法
     */
    @Value("${test}")
    private String testValue;

    /**
     * @Value默认值用法
     * 当application.properties文件没有相关属性时使用默认值
     */
    @Value("${testDefault:This is default value(默认值)}")
    private String defaultValue;

    @Override
    public void outPut() {
        try {
            System.out.println(testValue);
            System.out.println(defaultValue);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
